package com.zhxh.nzpos.login;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.zhxh.nzpos.Constants;
import com.zhxh.nzpos.R;

/**
 * 操作员登录界面，登录后进入主界面@MainActivity
 * @author wangzt
 *
 */
public class LoginActivity extends Activity {

	private String mPassword;
	
	private EditText mPasswordET;
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_opetator_login);
        initViews();
    }
	
	private void initViews() {
		Intent intent = getIntent();
		String card = intent.getStringExtra(Constants.OPERATOR_CARD);
		EditText cardET = (EditText)findViewById(R.id.operator_card_et);
		cardET.setText(card);
		
		mPasswordET = (EditText) findViewById(R.id.operator_password_et);
		
		mPassword = intent.getStringExtra(Constants.OPERATOR_PASSWORD);
		
		Button  okBtn = (Button) findViewById(R.id.operator_login_ok_btn);
		okBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Editable et = mPasswordET.getText();
				if (et != null) {
					String password = et.toString();
					if (password != null && password.equals(mPassword)) {
						Intent intent = new Intent();
						intent.setClass(getApplicationContext(), MainActivity.class);
						startActivity(intent);
						finish();
					} else {
						Toast.makeText(getApplicationContext(), getString(R.string.password_error), Toast.LENGTH_SHORT).show();
					}
				} else {
					Toast.makeText(getApplicationContext(), getString(R.string.password_blank), Toast.LENGTH_SHORT).show();
				}
				
				// 测试使用
	/*			Intent intent = new Intent();
				intent.setClass(getApplicationContext(), MainActivity.class);
				startActivity(intent);
				finish();*/
			}
		});
		
		Button  cancelBtn = (Button) findViewById(R.id.operator_login_cancel_btn);
		cancelBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(getApplicationContext(), LoginActivity.class);
				startActivity(intent);
				finish();
			}
		});
	}
}
